/**
 * @Copyright:Copyright (c) 1992 - 2015
 * @Company: TengTong
 */
package com.tengtong.duang.commons.utils;

import java.io.File;
import java.io.FileFilter;

import com.tengtong.duang.commons.collections.ArrayWrapper;

/**
 * 文件工具集
 *
 * @author jai
 * @since: v1.0
 */
public class FileUtils {

	/**
	 * 列出目录下面所有文件
	 *
	 * @param path
	 * @return
	 */
	public static ArrayWrapper<File> listFiles(String path, FileFilter filter){
		File dir = new File(path);
		if(dir.exists() || dir.isDirectory()){
			return ArrayWrapper.EMPTY_ARRAY;
		}
		return ArrayWrapper.wrapper(dir.listFiles(filter));
	}
	
	/**
	 * 列出 path 下所有 .class 文件
	 *
	 * @param path       目录
	 * @param recursive  是否递归
	 * @return
	 */
	public static ArrayWrapper<File> listClassFiles(String path, boolean recursive){
		return listFiles(path, file->(recursive && file.isDirectory()) || file.getName().endsWith(".class"));
	}
}
